import axios from 'axios'
import baseUrl from '@/baseUrl'
import Header from '@/components/header/header.vue'
// import mTitle from '@/components/mtitle/mtitle'
import { Tree, Dialog, Button } from 'element-ui'
// import mContent from '@/components/mainContent/mainContent'
export default {
  name: 'contactBooks',
  created () {
    axios.get(`${baseUrl}/${this.$route.name}`)
      .then((res) => {
        const str1 = JSON.stringify(res.data).replace(/name/g, 'label')
        const str2 = str1.replace(/department/g, 'children')
        const str3 = str2.replace(/staff/g, 'children')
        this.data = JSON.parse(str3)
      })
  },
  methods: {
    handleNodeClick (data) {
      console.log(data)
      this.tips.address = data.address ? data.address : this.tips.address
      this.tips.position = data.position ? data.position : this.position
      if (!data.children) {
        this.tips.rome = data.rome
        this.tips.name = data.label
        this.tips.phone = data.phone
        this.tips.describe = data.describe
        this.dialogVisible = true
      }
      console.log(this.tips, '+++')
    },
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.tips.address = ''
          this.tips.position = ''
          done()
        })
        .catch(_ => {})
    }
  },
  components: {
    Header,
    // mTitle,
    ElTree: Tree,
    ElDialog: Dialog,
    ElButton: Button
    // mContent
  },
  data () {
    return {
      tips: {
        address: '',
        position: ''
      },
      dialogVisible: false,
      data: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  }
}

/** 暂时无用 */
// leftTitle: {
//   bigTitle: '通讯录',
//   smallTitle: [{
//     route: '/contactBooks/address1',
//     routeTitle: '通讯录1'
//   }, {
//     route: '/contactBooks/address2',
//     routeTitle: '通讯录2'
//   }, {
//     route: '/contactBooks/address3',
//     routeTitle: '通讯录3'
//   }]
// }
